/* 
 * File:   AveragePixelHue.cpp
 * Author: guilhermemg
 * 
 * Created on 7 de Dezembro de 2011, 09:06
 */

#include "AveragePixelHue.h"

AveragePixelHue::AveragePixelHue() : Average() {
    setName("f4");
    setLargeName("f4 - averagePixelHue");
}

AveragePixelHue::AveragePixelHue(const AveragePixelHue& orig) : Average(orig) {
}

AveragePixelHue::~AveragePixelHue() {
}

void AveragePixelHue::calculates() {
    double sum = 0;
    
    for(int i = 0; i < this->getImage()->height; i++) {
        uchar* ptr = (uchar*)(this->getImage()->imageData + i*this->getImage()->widthStep);
        for(int j = 0; j < this->getImage()->width; j++) {
            sum += ptr[3*j];
        }
    }
    sum = 2*sum;
    
    // faz a media aritmetica para a imagem toda
    setValue(sum/(double)(this->getImage()->height * this->getImage()->width));
}



